package me.hl.time;

import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;

/**
 * Created by Planck on 2016/1/30.
 */
public class LocalDateDemo {


    @Test
    //地区选择
    public void zone() {
        ZoneId zone1 = ZoneId.of("Europe/Berlin");
        System.out.println(zone1.getRules());
    }

    @Test
    public void between() {
        //当前时区时间
        LocalDateTime now1 = LocalDateTime.now();
        //柏林时间
        LocalDateTime now2 = LocalDateTime.now(ZoneId.of("Europe/Berlin"));
        System.out.println(now1);
        System.out.println(now2);
        //返回一个新的改变了部分时间日期的对象
        LocalDateTime now3 = now1.withHour(18);

        LocalDateTime now4 = LocalDate.now().atTime(6, 10, 14, 222000000);
        System.out.println(now3);
        System.out.println(now4);

        long hours = ChronoUnit.HOURS.between(now1, now2);
        long minites = ChronoUnit.MINUTES.between(now1, now2);
        System.out.println(hours + "  " + minites);
    }

    @Test
    public void equal() throws Exception {
        LocalDate now1 = LocalDate.now();
        LocalDate now2 = LocalDate.now();
        System.out.println(now1.equals(now2));
        LocalDateTime now3 = LocalDateTime.now();
        Thread.sleep(1);
        LocalDateTime now4 = LocalDateTime.now();
        System.out.println(now3.equals(now4));
    }
}
